<script setup>
import {saveApi} from "@/api/RoleAPI";
import MyForm from "@/components/MyForm.vue";
import {onMounted, shallowReactive, shallowRef} from "vue";
import {RULE} from "@/const";
import MyNav from "@/components/MyNav.vue";
import router from "@/router";

// 表单数据 + 表单规则
let items = shallowRef([
  {'label': '角色标题', 'prop': 'title', 'required':true},
  {'label': '角色描述', 'prop': 'info', 'type': 'textarea'},
]);
let data = shallowReactive({});
let rules = {
  'title': RULE.COMM_TITLE,
  'info': RULE.COMMON_INFO,
};

function success() {
  setTimeout(() => router.push('/Role'), 1000);
}


/*======================= 加载函数 ===========================*/


</script>

<template>

  <my-nav :items="[
    {'icon': 'User', 'label': '角色管理'},
    {'icon': 'User', 'label': '角色列表', 'url': '/Role'},
    {'icon': 'User', 'label': '添加角色'},
  ]"/>

  <div class="role-insert-body">
    <my-form type="insert"
             :span="1"
             :items="items"
             :data="data"
             :rules="rules"
             :api="saveApi"
             :fn="success"
    />
  </div>

</template>

<style scoped lang="scss">

.role-insert-body {
  margin-top: 50px;
}

</style>